package com.hkbigdata.sybx.service;

import com.hkbigdata.sybx.mapper.UserPhoneMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yangjing
 * @creat 2025-05-27-9:05
 * @email 3010335359@qq.com
 */
@Service
public class UserPhoneService {

    private final UserPhoneMapper userPhoneMapper;

    public UserPhoneService(UserPhoneMapper userPhoneMapper) {
        this.userPhoneMapper = userPhoneMapper;
    }

    /**
     * 根据用户ID获取手机号
     * @param userId 用户ID
     * @return 包含手机号的结果Map
     */
    public Map<String, Object> getPhoneByUserId(String userId) {
        Map<String, Object> result = new HashMap<>();
        Map<String, Object> userData = userPhoneMapper.getUserPhoneById(userId);

        if (userData != null && !userData.isEmpty()) {
            result.put("code", 200);
            result.put("message", "获取成功");
            result.put("data", userData);
        } else {
            result.put("code", 404);
            result.put("message", "用户不存在");
        }
        return result;
    }

    /**
     * 获取所有用户手机号
     * @return 包含所有用户手机号的结果列表
     */
    public Map<String, Object> getAllUserPhones() {
        Map<String, Object> result = new HashMap<>();
        List<Map<String, Object>> userList = userPhoneMapper.getAllUserPhones();

        if (userList != null && !userList.isEmpty()) {
            result.put("code", 200);
            result.put("message", "获取成功");
            result.put("data", userList);
        } else {
            result.put("code", 404);
            result.put("message", "没有找到用户数据");
        }
        return result;
    }
}